#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
调试路径计算的脚本
"""

import os

def debug_path_calculation():
    current_dir = os.getcwd()
    print(f"当前工作目录: {current_dir}")

    # 测试几个文件
    test_files = [
        "general/ADX视频批量下载.user_v1.1_basic.user.js",
        "红果短剧/P助手(红果).user_v1.0.1_enhanced.user.js"
    ]

    for test_file in test_files:
        file_path = os.path.join(current_dir, test_file)
        print(f"\n文件: {test_file}")
        print(f"完整路径: {file_path}")
        print(f"文件存在: {os.path.exists(file_path)}")

        if os.path.exists(file_path):
            filename = os.path.basename(file_path)
            rel_path = os.path.relpath(file_path, current_dir)
            dir_part = os.path.dirname(rel_path)

            print(f"文件名: {filename}")
            print(f"相对路径: {rel_path}")
            print(f"目录部分: {dir_part}")

            # 构建URL路径
            url_path = rel_path.replace('\\', '/').replace(filename, f"encoded_{filename}")
            print(f"URL路径: {url_path}")

            # 构建meta文件名
            if dir_part and dir_part != '.':
                dir_name = dir_part.replace('\\', '_').replace('/', '_')
                meta_filename = f"{dir_name}_{filename.replace('.user.js', '.json')}"
            else:
                meta_filename = filename.replace('.user.js', '.json')
            print(f"Meta文件名: {meta_filename}")

if __name__ == "__main__":
    debug_path_calculation()
